<?php
//error_reporting(0);
include("function.php");
include("timeline.class.php");
//include("mail/sendmail.php");
//判断登陆
judgeLogin();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<meta http-equiv="X-UA-Compatible" content="IE=7" /><!--如果是IE8时强制以IE7显示-->
<meta name="keywords" content="食品笔记,食品,食品安全,饮食,饮食安全,生活"><!--SEO关键字-->
<meta name="description" content="食品笔记，你的饮食安全卫士"><!--SEO描述-->
<link rel="shortcut icon" type="image/ico" href="images/favicon.ico"><!--选项卡图标-->
<title>食品笔记 - 让生活更健康</title>
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/style.css">

<!--[if ie]>
<link rel="stylesheet" href="css/ie.css">
<script type="text/javascript" src="js/DD_belatedPNG.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('.png');/*在需要png透明的元素里面加上.png样式即可（class="png"）*/
</script>
<![endif]-->
</head>
<body>
	<div class="header w pr"><!-- header -->
		<div class="index-header w960 bc pr">
			<a href="home.php" class="score_logo score_img dib png fl mt10"></a>
			<div class="header_right fr">
				<ul class="header_nav fl tc fb f12 h mt5">
					<li><a href="home.php">首 页</a></li>
					<li><a href="report.php">饮食报告</a></li>
					<li><a href="newsmap.php">食品新闻</a></li>
					<li><a href="food.php">选食专栏</a></li>
					<li><a href="timeline.php" class="header_nav_hover">时光轴</a></li>
					<li><a href="share.php">分享</a></li>
				</ul>
				<a href="massage.php" class="header_myMessage tc fr ml5" title="私信"><?php echo showCountMassage($_SESSION['login_mail']);?></a><!-- 私信 -->
				
				<div class="header_myInfo fr f14 h pr">
					<a href="#" class="header_setup"><img src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" class="fl" /></a><!-- user_avatar -->
					<a href="#" class="fl header_setup"><?php echo showUserName();?></a><!-- user_nickname -->
					<div class="header_myInfoArrow score_img fl"></div>
					<ul class="header_hideInfo none pa tc w"><!-- hide_info -->
						<li><a href="#" class="header_setup">个人设置</a></li>
						<li><a href="modifymail.php">修改邮箱</a></li>
						<li><a href="password.php">修改密码</a></li>
						<li><a href="login_out.php">退出登录</a></li>
					</ul>
				</div>
				
			</div>
		</div>
	</div><!-- end_header -->

	<div class="score_main pr oh h pb100"><!-- time-line -->
		<div class="main w800 bc pr mt100 oh">
			<div class="tl_timewrap pr oh">
				<ul class="tl_numberDate tc oh">
				<?php
					$sql = "SELECT * FROM `food_user_score` WHERE `user_id` = $myId ORDER BY `create_time` DESC";
					$query_2 = mysql_query($sql)or die(mysql_error());
					$score_sum = 0;
					while($row_score = mysql_fetch_array($query_2)){
						$score[] = array('score'=>$row_score['user_score'],'time'=>$row_score['create_time'],'tip'=>$row_score['tip'],'additiveNum'=>$row_score['additiveNum'],'newsExposure'=>$row_score['newsExposure']);
					$timeArr = explode(' ',$score[$score_sum]['time']);
						$score[$score_sum]['time'] = $timeArr[0];
						$timeArr2 = explode('-',$score[$score_sum]['time']);
				?>
					<li class="pa pb20"><?php echo (int)$timeArr2[0]."-".(int)$timeArr2[1]."-".(int)$timeArr2[2];?></li>
				<?php
						$score_sum++;
					}
				?>
				</ul >
				<div class="tl_lineLeft pa w100 png"></div><div class="tl_lineRight pa w100 png"></div>
			</div>
			
			<ul class="tl_contentUl oh">
			<?php
				for($i=0;$i<$score_sum;$i++){
			?>
				<li class="tl_content mt50 fl oh">
					<div class="score_yourScore score_img cf fl png ml100">
						<span><?php echo $score[$i]['score'];?>'</span>	
					</div>
					<div class="tl_recordText fl ml40">
					<?php
						$thisTime = $score[$i]['time'];
						$thisTime = explode('-',$score[$i]['time']);
					?>
						<h2 class="tl_detailedDate f24"><?php echo (int)$thisTime[0];?>年<?php echo (int)$thisTime[1];?>月<?php echo (int)$thisTime[2];?>日</h2>
						<?php
					 	$date = $score[$i]['time'];
					//	print_r($score[$i]);
						$sql = "SELECT * FROM `food_user_data` WHERE `user_id` = $myId AND `create_time` like '$date%'";
						$query_3 = mysql_query($sql)or die(mysql_error());
						$total = mysql_num_rows($query_3);
						?>
						<p class="tl_easyRecord mt20"><?php echo '你今天记录了'.$total.'种食品，有'.strip_tags($score[$i]['additiveNum']).'种添加剂超标';?></p>
						<h3 class="tl_detailRecord mt30 f18 pb5">详情</h3>
						<table class="tl_detailedList mt10">
							<tr>
								<td class="tl_tableTitle">食 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;品：</td>
								<td class="ti_tableContent">
								<?php
									while($row_eat = mysql_fetch_array($query_3)){
								?>
									<span class="tl_unit"><a href=""><?php echo $row_eat['eatwhat'];?></a>-<?php echo $row_eat['eathowmany'];?>kg</span>
								<?php
									}
								?>
								</td>
							</tr>
							<tr>
								<td class="tl_tableTitle">添加剂超标：</td>
								<td class="ti_tableContent"><a href="" class="tl_unit tl_warm"><?php echo strip_tags($score[$i]['additiveNum']); ?></a></td>
							</tr>
							<tr>
								<td class="tl_tableTitle">新 闻 曝 光：</td>
								<td class="ti_tableContent"><a href="" class="tl_unit tl_warm"><?php echo $score[$i]['newsExposure'];?></a></td>
							</tr>
						</table>
					</div>
				</li>
			<?php
				}
			?>
				<!--<li class="tl_content mt50 fl oh">
					<div class="score_yourScore score_img cf fl png ml100">
						<span>86'</span>	
					</div>
					<div class="tl_recordText fl ml40">
						<h2 class="tl_detailedDate f24">2012年8月6日</h2>
						<p class="tl_easyRecord mt20">您当日记录了3种食品，有1项添加剂超标，2种食品被新闻曝光过。</p>
						<h3 class="tl_detailRecord mt30 f18 pb5">详情</h3>
						<table class="tl_detailedList mt10">
							<tr>
								<td class="tl_tableTitle">食 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;品：</td>
								<td class="ti_tableContent"><span class="tl_unit"><a href="">蒙牛内蒙古老酸奶</a>-0.12kg</span><span class="tl_unit"><a href="">德芙白巧克力</a>-0.05kg</span></td>
							</tr>
							<tr>
								<td class="tl_tableTitle">添加剂超标：</td>
								<td class="ti_tableContent"><a href="" class="tl_unit tl_warm">亚硝酸钠</a></td>
							</tr>
							<tr>
								<td class="tl_tableTitle">新 闻 曝 光：</td>
								<td class="ti_tableContent"><a href="" class="tl_unit tl_warm">蒙牛内蒙古老酸奶</a></td>
							</tr>
						</table>
					</div>
				</li>
				<li class="tl_content mt50 fl oh">
					<div class="score_yourScore score_img cf fl png ml100">
						<span>65'</span>	
					</div>
					<div class="tl_recordText fl ml40">
						<h2 class="tl_detailedDate f24">2012年8月6日</h2>
						<p class="tl_easyRecord mt20">您当日记录了3种食品，有1项添加剂超标，2种食品被新闻曝光过。</p>
						<h3 class="tl_detailRecord mt30 f18 pb5">详情</h3>
						<table class="tl_detailedList mt10">
							<tr>
								<td class="tl_tableTitle">食 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;品：</td>
								<td class="ti_tableContent"><span class="tl_unit"><a href="">蒙牛内蒙古老酸奶</a>-0.12kg</span><span class="tl_unit"><a href="">德芙白巧克力</a>-0.05kg</span></td>
							</tr>
							<tr>
								<td class="tl_tableTitle">添加剂超标：</td>
								<td class="ti_tableContent"><a href="" class="tl_unit tl_warm">亚硝酸钠</a></td>
							</tr>
							<tr>
								<td class="tl_tableTitle">新 闻 曝 光：</td>
								<td class="ti_tableContent"><a href="" class="tl_unit tl_warm">蒙牛内蒙古老酸奶</a></td>
							</tr>
						</table>
					</div>
				</li>-->
			</ul>
			<div class="tl_prev pa png js_tl_change"></div>
			<div class="tl_next pa png js_tl_change"></div>
		</div>
	</div><!-- end_score_main -->

	<div class="footer w"><!-- footer -->
		<div class="w960 bc pr">
			<div class="pt30 welcome-footer bc">
				<span class="iphone-app-img dib png fl"></span><a href="#" class="iphone-app f12 a3 fl">iphone应用</a><a href="foodnote.apk" class="android-app f12 a3 fr">android应用</a><span class="android-app-img dib png fr"></span>
			</div>
			<div class="welcome-about mb10">
				<p class="f12 tc"><a href="#" class="a3">关于我们</a><span class="ml10 mr10">|</span><a href="#" class="a3">使用条款</a><span class="ml10 mr10">|</span><a href="#" class="a3">常见问题</a></p>
			</div>
			<div class="welcome-about f12 tc">
				<p class="a3 f12 c91">Copyright &copy; 2011-2012 Foodnote&nbsp;&nbsp;&nbsp;&nbsp; 湘ICP备09004495号-5</p>
			</div>
		</div>
	</div><!-- end_footer -->
	
	<?php
		//判断是否新用户登录
		$login_mail = $_SESSION['login_mail'];
		$login_status = judgeNewUser($login_mail);
		
		//获取用户数据
		$userData = getUserBasicInfo($_SESSION['login_mail']);
		
		if($login_status == 0)
		{
			echo "<div class='novice_login png pa w'>";
		}else
		{
			echo "<div class='novice_login png pa w none'>";
		}
	?>
		<div class="personal_info bc oh pb50 pr">
			<div class="personal_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">个人信息录入</h2>
			
			<form action="home.php" method="post" class="ml50">
				<fieldset class="fl">
					<p class="mt10"><label for="" class="personal_label f22">性别</label></p>
					<p class="mt10"><small class="personal_small f14">请选择：男/女</small></p>
					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="sex">
					<?php  
						if($userData['user_sex']=="男"):
						
							echo "<option value='男' selected >男</option>";
							echo "<option value='女'>女</option>";
						
						elseif($userData['user_sex']=="女"):
						
							echo "<option value='男'>男</option>";
							echo "<option value='女' selected>女</option>";
						
						else:
						
							echo "<option value='' selected>--</option>";
							echo "<option value='男'>男</option>";
							echo "<option value='女'>女</option>";
						endif;
					?>
								
						</select>
					</p>
					<p class="mt10"><label for="" class="personal_label f22">年龄</label></p>
					<p class="mt10"><small class="personal_small f14">不同的年龄对饮食的需求不同，例如:23</small></p>
					<p class="mt10"><input type="text" class="score_text zy_ageVal pl5 pr5" name="age" value="<?php echo $userData['user_age'];?>"/></p>
					<p class="mt10"><label for="" class="personal_label f22">现居地</label></p>
					<p class="mt10"><small class="personal_small f14">请输入您现居地的省份名，例如:湖南</small></p>

					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="city">
							<option value='<?php echo $userData['user_city'];?>' selected><?php echo $userData['user_city'];?></option>
							<option value='安徽'>安徽</option>
							<option value='福建'>福建</option>
							<option value='港澳台藏'>港澳台藏</option>
							<option value='甘肃'>甘肃</option>
							<option value='广东'>广东</option>
							<option value='广西'>广西</option>
							<option value='贵州'>贵州</option>
							<option value='海南'>海南</option>
							<option value='河北'>河北</option>
							<option value='黑龙江'>黑龙江</option>
							<option value='河南'>河南</option>
							<option value='湖北'>湖北</option>
							<option value='湖南'>湖南</option>
							<option value='江苏'>江苏</option>
							<option value='江西'>江西</option>
							<option value='吉林'>吉林</option>
							<option value='辽宁'>辽宁</option>
							<option value='内蒙古'>内蒙古</option>
							<option value='宁夏'>宁夏</option>
							<option value='青海'>青海</option>
							<option value='山东'>山东</option>
							<option value='山西'>山西</option>
							<option value='陕西'>陕西</option>
							<option value='四川'>四川</option>
							<option value='云南'>云南</option>
							<option value='新疆'>新疆</option>
							<option value='浙江'>浙江</option>
							<option value='直辖市'>直辖市</option>
						</select>
					</p>

					<p class="mt10"><label for="" class="personal_label f22">体重</label></p>
					<p class="mt10"><small class="personal_small f14">不同的体重对饮食的需求不同，单位：kg</small></p>
					<p class="mt10"><input type="text" class="score_text zy_weightVal pl5 pr5" name="weight" value="<?php echo $userData['weight'];?>"/> kg</p>
					<input type="hidden" value="<?php echo basename($_SERVER['PHP_SELF']);?>" name="fileName" />
					<input type="hidden" value="true" name="submited" />
					<input type="submit" value="确认提交" name="submit" class="personal_submit pa f18" />
				</fieldset>
			</form>
			<form method="post" action ="upload.php" enctype="multipart/form-data" target="hidden_frame" class="none">
				<fieldset>
					<input type="file" name="photo" id="photo" onchange="cli('p_submit');"/>
					<input type="submit" name="p_submit" value="保存" id="p_submit">
					<iframe name='hidden_frame' id="hidden_frame" style="border:none;" onreadystatechange="reflesh('<?php echo $_SESSION[login_mail]?>');"></iframe>
				</fieldset>
			</form>
			<form action="home.php" method="post" class="ml50">
				<fieldset>
					<a href="javascript:void(0)" onclick="cli('photo');"><img id="img" src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" class="personal_avatar pa" />
					<span class="pa click_upload">+点击上传头像</span>
					</a>
					<a href="javascript:void(0)" class="pa avatar_refresh" onclick="reflesh('<?php echo $_SESSION[login_mail]?>');">刷新</a>
				</fieldset>
			</form>
		</div>
	</div>
	
	<?php //qq_state 
	$qq_status = qq_status($login_mail); 
	if(isset($_SESSION['qq_nickname']) && $qq_status == 0):
	?>
	<div class="qq_tips_bg png pa w"><!-- QQ登陆提醒 -->
		<div class="qq_tips bc oh pb50 pr">
			<div class="qq_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">温馨提示</h2>
			<div class="qq_tipsh oh ml50 f14">
				<img src="images/tips_smile.png" alt="" class="fr png mr150" /><!-- 提示图片 -->
				<p>亲爱的</span class="a69"><?php echo $_SESSION['qq_nickname']; ?></span></p>
				<input type="hidden" class="qq_user_mail" value="<?php echo $login_mail;?>">
				<p>欢迎来到<span class="a69">食品笔记</span></p>
				<p>你的登陆账号为:<?php echo $_SESSION['login_mail'];?></p>
				<p>密码为:<?php echo $_SESSION['user_prepassword'];?></p>
				<p>为了方便下次登录，请即时<a href="password.php">修改密码</a>。</p>
			</div>
		</div>
	</div>
	<?php endif;?>
	
	<div id="scroeLoading" class="none png">
		<div class="loadingCenter bc pr">
			<div class="scoreLoading_bar bc pr"><div class="scoreLoading_cover pa"></div></div>
			<p class="loadingTips mt20 bc tc"></p>
		</div>
	</div>
	
	<!-- JavaScript -->
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
	<?php if(!empty($_SESSION['qq_nickname'])){ ?>
<script type="text/javascript">  
	$(document).ready(function(){
		$('.qq_tips').show();
		
		$('.qq_close').click(function(event){
			$('.qq_tips_bg').hide();
		});
	})
</script>
	<?php } ?> 
<script type="text/javascript">  
 
 function cli(id){  
		var sub = document.getElementById(id);
   sub.click();  
//   if (/msie/i.test(navigator.userAgent)) //IE  
//   {  
//      sub.fireEvent("onclick");  
//   } else {  
//      var e = document.createEvent('MouseEvent');  
//      e.initEvent('click', false, false);  
//      sub.dispatchEvent(e);  
//   }
}

function reflesh(user){
	image_src="image.php?user_mail="+user+"&math="+Math.random(1);
	//alert(image_src);
	document.getElementById("img").src=image_src;
	
	}	

</script> 
<div class="none">
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fbba169f4f4508eb5cc1c5618eeb3c59d' type='text/javascript'%3E%3C/script%3E"));
</script>
</div>
</body>

</html>
